#include "btform.h"
#include "ui_btform.h"

btform::btform(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::btform)
{
    ui->setupUi(this);
    // 设置line1的动画效果
    ui->lineBox->hide();
    animationLine1 = new QPropertyAnimation(ui->line1, "geometry", this);
    animationLine1->setDuration(1500);
    animationLine1->setKeyValueAt(0, QRect(31, 21, 2, 0));
    animationLine1->setKeyValueAt(0.5, QRect(31, 6 ,2, 15));
    animationLine1->setKeyValueAt(1, QRect(31, 21, 2, 0));
    animationLine1->setLoopCount(-1);
    animationLine1->start();
        // 设置line2的动画效果
    animationLine2 = new QPropertyAnimation(ui->line2, "geometry", this);
    animationLine2->setDuration(1600);
    animationLine2->setKeyValueAt(0, QRect(38, 21, 2, 0));
    animationLine2->setKeyValueAt(0.5, QRect(38, 6, 2, 15));
    animationLine2->setKeyValueAt(1, QRect(38, 21, 2, 0));
    animationLine2->setLoopCount(-1);
    animationLine2->start();
    // 设置line3的动画效果
    animationLine3 = new QPropertyAnimation(ui->line3, "geometry", this);
    animationLine3->setDuration(1700);
    animationLine3->setKeyValueAt(0, QRect(43, 21, 2, 0));
    animationLine3->setKeyValueAt(0.5, QRect(43, 6, 2, 15));
    animationLine3->setKeyValueAt(1, QRect(43, 21, 2, 0));
    animationLine3->setLoopCount(-1);
    animationLine3->start();
    // 设置line4的动画效果
    animationLine4 = new QPropertyAnimation(ui->line4, "geometry", this);
    animationLine4->setDuration(1800);
    animationLine4->setKeyValueAt(0, QRect(48, 21, 2, 0));
    animationLine4->setKeyValueAt(0.5, QRect(48, 6, 2, 15));
    animationLine4->setKeyValueAt(1, QRect(48, 21, 2, 0));
    animationLine4->setLoopCount(-1);
    animationLine4->start();
}

btform::~btform()
{
    delete ui;
}

void btform::seticon(QString btIcon, QString content, int mid)
{
    // 设置⾃定义按钮的图⽚、⽂字、以及id
    ui->btIcon->setPixmap(QPixmap(btIcon));
    ui->btText->setText(content);
    this->id = mid;

}

int btform::getId()
{
    return  id;
}

void btform::showAnimal()
{
    // 显⽰linebox, 设置颜⾊为绿⾊
    ui->lineBox->show();

}


void btform::clearBg()
{
    // 清除上⼀个按钮点击的背景效果,恢复之前的样式
  ui->btStyle->setStyleSheet("background-color:#F5F5F5;");
    ui->lineBox->hide();
}



void btform::mousePressEvent(QMouseEvent *event)
{
    // 告诉编译器不要触发警告
    (void)event;
    // ⿏标点击之后，背景变为绿⾊，⽂字变为⽩⾊
    ui->btStyle->setStyleSheet("background-color:rgb(30,206,154);color:#F6F6F6;border:none}");
    showAnimal();
    emit click(this->id); // 发送⿏标点击信号



}



